<template>
  <PageWrapper :contentStyle="{ margin: 0 }">
    <BasicTable @register="registerOpe">
      <template #form-typeid>
        <DateButtonGroup
          :isSelect="'days'"
          :compareRangeTime="unixRang"
          :dateGroupButtonList="dateGroupButtonList"
          @change-button-day="changeButtonDay"
          style="margin-right: 8px"
        />
      </template>
      <template #form-custom>
        <InputGroup class="!flex" compact style="width: 380px">
          <Select style="width: 50%" v-model:value="currentType">
            <SelectOption :value="1"> {{ $t('table.system.system_member_account') }} </SelectOption>
            <SelectOption :value="2">{{ $t('table.risk.report_login_ip') }}</SelectOption>
            <SelectOption :value="3">{{ $t('table.member.member_login_demond') }}</SelectOption>
          </Select>
          <Input
            style="width: 50%; margin-right: 10px"
            allowClear
            :placeholder="$t('common.chooseText')"
            v-model:value="fromSearch"
          />
        </InputGroup>
      </template>
    </BasicTable>
  </PageWrapper>
</template>

<script setup lang="ts">
  import { ref, nextTick, onMounted } from 'vue';
  import { PageWrapper } from '/@/components/Page';
  import { BasicTable, useTable } from '/@/components/Table';
  import { columns, searchFormSchema, dateGroupButtonList } from './operate.data';
  import { getuOperationList } from '/@/api/member/index';
  import { setEndformatDate, setStartformatDate } from '/@/utils/dateUtil';
  import { useExportFile } from '/@/utils/helper/paramsHelper';
  import { DateButtonGroup } from '/@/components/DateButtonGroup/index';
  import { InputGroup, Select, SelectOption, Input } from 'ant-design-vue';
  import eventBus from '/@/utils/eventBus';
  import { useI18n } from '/@/hooks/web/useI18n';
  import dayjs from 'dayjs';

  const { t } = useI18n();
  //输入当前的值
  const fromSearch = ref('' as any);
  //定义当前选中的框
  const currentType = ref<any>(1);
  const unixRang = ref<Array<number>>([]);
  const { exportFile } = useExportFile();
  const [registerOpe, { getForm, reload }] = useTable({
    api: getuOperationList,
    columns,
    bordered: true,
    useSearchForm: true,
    showIndexColumn: false,
    beforeFetch: (param) => {
      param['search_type'] = currentType.value;
      param['search_value'] = fromSearch.value;
    },
    formConfig: {
      //labelWidth: 120,
      schemas: searchFormSchema,
      showAdvancedButton: false,
      showResetButton: false,
      actionColOptions: {
        // class: 't-form-col',
        class: 'button-box t-form-label-com',
        // xxl: 12,
        // xl: 12,
        // lg: 12,
      },
      //fieldMapToTime: [['data', ['sts', 'ets'], 'YYYY-MM-DD']],

      // resetButtonOptions: {
      //   text: t('business.common_export'),
      // },
      // resetFunc: handleExportTableList,
    },
  });

  function changeButtonDay(value) {
    nextTick(async () => {
      await getForm().setFieldsValue({ time: [value[0], value[1]] });
      // await getForm().setFieldsValue({ end_time: value[1] });
      reload();
    });
  }
  function reSetButtonBox() {
    if (document.getElementsByClassName('button-box').length > 0) {
      for (var i = 0; i < document.getElementsByClassName('button-box').length; i++) {
        document.getElementsByClassName('button-box').item(i).classList.remove('ant-col-4');
      }
    }
  }
  onMounted(() => {
    reSetButtonBox();
  });
  // async function handleExportTableList(): Promise<void> {
  //   try {
  //     const { validate } = getForm();
  //     const values = await validate();
  //     if (values?.data?.length > 0) {
  //       values.start_time = values.data[0] ? setStartformatDate(values.data[0]) : null;
  //       values.end_time = values.data[1] ? setEndformatDate(values.data[1]) : null;
  //     }
  //     delete values.data;
  //     //await exportFile(ExportUserLogExport, values, '操作日志');
  //   } catch (e) {
  //     console.log(e);
  //   }
  //   // 避免匯出後自動查詢
  //   return Promise.reject();
  // }
  // eventBus.on('mittChange', (rangTime: any) => {
  //   const startTime = rangTime[0] ? dayjs(rangTime[0]).toDate().getTime() : 0;
  //   const endTime = rangTime[1] ? dayjs(rangTime[1]).toDate().getTime() : 0;
  //   unixRang.value = [startTime, endTime];
  // });
</script>
<style scoped>
  .ant-input-group.ant-input-group-compact > .ant-select-focused {
    z-index: 0;
  }
</style>
